Skip to content

test: add comprehensive unit tests to double coverage#111

Merged
async3619 merged 7 commits intodevfrom
async3619/add-missing-tests
Mar 28, 2026
Merged

test: add comprehensive unit tests to double coverage#111
async3619 merged 7 commits intodevfrom
async3619/add-missing-tests

Conversation

@async3619
Copy link
Copy Markdown
Owner

Summary

  • Add comprehensive unit tests across 15 spec files, expanding from minimal placeholder tests to thorough coverage of all branches and logic paths.
  • Statement coverage improved from ~27% to ~56%, with most targeted modules reaching 80-100% coverage.
  • Key modules now fully or near-fully tested: color.ts (100%), react/usage.ts (100%), json/deps.ts (100%), react/bindings.ts (97.5%), ascii/import.ts (98%), react/file.ts (97%), react/entries.ts (93%), react/walk.ts (93%), react/symbols.ts (93%), react/references.ts (91%).
  • Tests use oxc-parser's parseSync to parse real TSX code snippets and validate against actual AST nodes rather than mocking.

Related Issue

N/A

Validation

  • pnpm run check
  • Commits follow Conventional Commits
  • Branch name follows codex/issue-<number>-<slug>
  • This PR will be Squash Merged into dev

Notes

  • Remaining low-coverage files (deps/diff.ts, deps/index.ts, react/diff.ts, app/cli.ts) require real git/filesystem operations and are better suited for E2E tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Add comprehensive unit tests across 15 spec files to double coverage

🧪 Tests

Grey Divider

Walkthroughs

Description
• Comprehensive expansion of unit test coverage across 15 spec files, improving statement coverage
  from ~27% to ~56%
• Key modules now achieve high coverage: color.ts (100%), react/usage.ts (100%), json/deps.ts
  (100%), react/bindings.ts (97.5%), ascii/import.ts (98%), react/file.ts (97%),
  react/entries.ts (93%), react/walk.ts (93%), react/symbols.ts (93%), react/references.ts
  (91%)
• Tests use oxc-parser's parseSync to parse real TSX code snippets and validate against actual
  AST nodes rather than mocking
• Added helper factory functions (createGraph, createFileAnalysis, createSymbolFromCode, etc.)
  for consistent and maintainable test setup
• Comprehensive coverage of all branches and logic paths including edge cases, circular references,
  and error conditions
• Note: Low-coverage files (deps/diff.ts, deps/index.ts, react/diff.ts, app/cli.ts) deferred
  to E2E tests due to git/filesystem operation requirements
Diagram
flowchart LR
  A["Minimal Placeholder Tests<br/>~27% Coverage"] -- "Expand with Real AST Parsing" --> B["Comprehensive Test Suites<br/>~56% Coverage"]
  B -- "15 Spec Files" --> C["High Coverage Modules<br/>80-100%"]
  C --> D1["React Analysis<br/>usage, file, entries, walk,<br/>symbols, references, bindings"]
  C --> D2["Output Formatting<br/>ascii/import, ascii/react,<br/>json/deps, json/react"]
  C --> D3["Utilities<br/>color"]
Loading

Grey Divider

File Changes

1. src/analyzers/react/references.spec.ts 🧪 Tests +572/-36

Comprehensive unit tests for React reference resolution

• Expanded from minimal placeholder test to comprehensive coverage of resolveReactReference,
 addExternalHookNodes, and addBuiltinNodes functions
• Added helper functions createFileAnalysis and createPendingSymbol for test setup
• Tests cover builtin resolution, local symbol lookup, imported symbol resolution, re-export chains,
 namespace members, and external hooks
• Includes tests for compareReactNodeIds and compareReactUsageEntries comparison functions

src/analyzers/react/references.spec.ts


2. src/analyzers/react/walk.spec.ts 🧪 Tests +349/-10

Comprehensive unit tests for React AST walking utilities

• Replaced single placeholder test with 13 focused test suites covering all exported functions
• Added helper functions parseExpression, parseStatement, parseJSXElement,
 parseCallExpression using oxc-parser
• Tests validate JSX element detection, hook/component naming conventions, styled-component
 handling, and tree walking logic
• Covers edge cases like builtin elements, member expressions, and nested function traversal

src/analyzers/react/walk.spec.ts


3. src/analyzers/react/queries.spec.ts 🧪 Tests +355/-47

Comprehensive unit tests for React usage graph queries

• Expanded from single placeholder test to 9 focused test suites for graph query functions
• Added createGraph helper factory for consistent test setup
• Tests cover entry filtering by kind, root detection with cycle handling, and usage filtering with
 missing node handling
• Validates deduplication of entry targets and zero-inbound node detection

src/analyzers/react/queries.spec.ts


View more (12)
4. src/output/ascii/import.spec.ts 🧪 Tests +422/-3

Comprehensive unit tests for ASCII dependency tree printing

• Replaced single placeholder test with 14 comprehensive test cases for printDependencyTree
• Added createGraph helper factory for dependency graph construction
• Tests cover simple trees, circular dependencies, shared dependencies,
 external/builtin/boundary/missing annotations, and reference kind prefixes
• Validates unused dependency omission and tree character formatting

src/output/ascii/import.spec.ts


5. src/output/json/import.spec.ts 🧪 Tests +331/-3

Comprehensive unit tests for JSON dependency tree serialization

• Expanded from single placeholder test to 12 comprehensive test cases for graphToSerializableTree
• Added createGraph helper factory for dependency graph setup
• Tests cover circular references, shared node deduplication, missing nodes, unused dependency
 omission, and boundary/builtin/missing kind serialization
• Validates external dependencies without nested nodes and proper metadata inclusion

src/output/json/import.spec.ts


6. src/analyzers/react/bindings.spec.ts 🧪 Tests +280/-2

Comprehensive unit tests for import/export binding collection

• Replaced single placeholder test with 20 focused test cases organized into 4 describe blocks
• Added createMockSymbol and collect helper functions using oxc-parser for real AST parsing
• Tests cover named/default/namespace imports, re-exports, export all, type-only filtering, and
 symbol mapping
• Validates renamed bindings, local exports, and default export handling

src/analyzers/react/bindings.spec.ts


7. src/output/ascii/react.spec.ts 🧪 Tests +303/-4

Comprehensive unit tests for ASCII React usage tree printing

• Replaced single placeholder test with 14 comprehensive test cases for React usage tree printing
• Added createGraph helper factory for React usage graph construction
• Tests cover entry printing, empty graph handling, circular references, alias display, kind
 filtering, and builtin file path display
• Includes 5 test cases for diff tree printing with change markers and circular node handling

src/output/ascii/react.spec.ts


8. src/output/ascii/deps.spec.ts 🧪 Tests +301/-4

Comprehensive unit tests for ASCII package dependency tree printing

• Replaced single placeholder test with 13 comprehensive test cases for package dependency tree
 printing
• Tests cover simple trees, workspace dependencies with paths/specifiers, circular references, and
 missing root nodes
• Includes 5 test cases for diff tree printing with added/removed/changed dependencies and version
 changes
• Validates tree character formatting and circular workspace reference handling

src/output/ascii/deps.spec.ts


9. src/color.spec.ts 🧪 Tests +166/-33

Comprehensive unit tests for color formatting utilities

• Expanded from single describe block with 3 tests to 7 focused describe blocks with 20+ test cases
• Added comprehensive tests for resolveColorSupport covering FORCE_COLOR, NO_COLOR, and TTY
 detection
• Tests validate color wrapping for unused markers, React symbol labels, and package diff changes
• Covers edge cases like multiple occurrences, color precedence, and disabled color mode

src/color.spec.ts


10. src/analyzers/react/symbols.spec.ts 🧪 Tests +184/-4

Comprehensive unit tests for React symbol collection

• Replaced single placeholder test with 18 comprehensive test cases organized into 2 describe blocks
• Added collectSymbols and collectDynamicCandidates helper functions using oxc-parser
• Tests cover function declarations, arrow functions, styled-components, dynamic component
 candidates, and export handling
• Validates filtering of non-React functions, lowercase names, and underscore-containing identifiers

src/analyzers/react/symbols.spec.ts


11. src/output/json/react.spec.ts 🧪 Tests +184/-4

Comprehensive unit tests for JSON React tree serialization

• Replaced single placeholder test with 8 comprehensive test cases for React tree serialization
• Added createGraph helper factory for React usage graph construction
• Tests cover entry serialization, nested usage handling, circular reference detection, and kind
 filtering
• Validates missing node filtering and diff graph serialization

src/output/json/react.spec.ts


12. src/analyzers/react/entries.spec.ts 🧪 Tests +119/-7

Comprehensive unit tests for React entry collection helpers

• Replaced placeholder tests with comprehensive test cases for createReactUsageLocation function
 covering edge cases (negative offsets, empty source text)
• Added extensive test suite for collectEntryUsages function using parseSync to parse real TSX
 code and validate AST traversal
• Tests cover component detection, hook calls, builtin element handling, nested components,
 deduplication, and various reference patterns (member expressions, React.createElement)

src/analyzers/react/entries.spec.ts


13. src/analyzers/react/usage.spec.ts 🧪 Tests +173/-2

Comprehensive unit tests for React symbol usage analysis

• Replaced minimal placeholder test with 15+ comprehensive test cases for analyzeSymbolUsages
 function
• Added helper function createSymbolFromCode to parse TSX code and create test symbols with proper
 AST nodes
• Tests cover component references, hook detection, builtin element handling, styled-component
 patterns, React.createElement, and multiple references in single functions

src/analyzers/react/usage.spec.ts


14. src/output/json/deps.spec.ts 🧪 Tests +174/-4

Comprehensive unit tests for JSON dependency serialization

• Replaced placeholder test with comprehensive test suite for graphToSerializablePackageTree
 covering root packages, workspace dependencies, circular references, and missing nodes
• Added extensive tests for diffGraphToSerializablePackageTree validating serialization of
 dependency diff graphs with change tracking and version comparisons
• Tests use realistic PackageDependencyGraph and PackageDependencyDiffGraph structures to
 validate transformation logic

src/output/json/deps.spec.ts


15. src/analyzers/react/file.spec.ts 🧪 Tests +136/-2

Comprehensive unit tests for React file analysis

• Replaced minimal placeholder test with 16+ comprehensive test cases for analyzeReactFile
 function
• Added helper function analyze to parse TSX code and invoke the analyzer with configurable
 options
• Tests cover component/hook detection, import/export binding collection, entry usage collection,
 symbol reference analysis, source dependency mapping, and builtin element handling

src/analyzers/react/file.spec.ts


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review bot commented Mar 28, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq bot commented Mar 28, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing async3619/add-missing-tests (2631555) with dev (2a76067)1

Open in CodSpeed

Footnotes

  1. No successful run was found on dev (ea885db) during the generation of this report, so 2a76067 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

async3619 and others added 2 commits March 28, 2026 17:39
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.16%. Comparing base (2a76067) to head (2631555).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #111      +/-   ##
==========================================
+ Coverage   66.13%   69.16%   +3.03%     
==========================================
  Files          39       39              
  Lines        2640     2640              
  Branches      873      873              
==========================================
+ Hits         1746     1826      +80     
+ Misses        525      479      -46     
+ Partials      369      335      -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

async3619 and others added 3 commits March 28, 2026 17:58
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…g, and pnpm-lock

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…diff

Raises unit test statement coverage from 62.7% to 81.9%.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@async3619 async3619 merged commit 22165f7 into dev Mar 28, 2026
5 checks passed
@async3619 async3619 deleted the async3619/add-missing-tests branch March 28, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant